package org.lisen.quartz.quartz;

import org.quartz.Job;
import org.quartz.JobDataMap;
import org.quartz.JobExecutionContext;
import org.quartz.SchedulerException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @author laughing
 * @date 2020/9/29
 * @site https://www.lisen.org
 */
public class PrintJobService implements Job {

    private final Logger logger = LoggerFactory.getLogger(PrintJobService.class);

    /**
     * 任务执行
     *
     * @param jobExecutionContext 任务执行信息
     */
    @Override
    public void execute(JobExecutionContext jobExecutionContext) {
        logger.info("准备获取scheduler参数");
        try {
            String schedulerValue = jobExecutionContext.getScheduler().getContext().getString("sKey");
            logger.info(schedulerValue);

        } catch (SchedulerException e) {
            e.printStackTrace();
        }
        logger.info("完成获取scheduler参数\n");
        logger.info("准备获取TriggerData");
        JobDataMap triggerDataMap = jobExecutionContext.getTrigger().getJobDataMap();
        for (String triggerKey : triggerDataMap.getKeys()) {
            logger.info(triggerDataMap.getString(triggerKey));
        }
        logger.info("完成获取TriggerData\n");
        logger.info("准备获取JobData");
        JobDataMap jobDataMap = jobExecutionContext.getJobDetail().getJobDataMap();
        for (String triggerKey : jobDataMap.getKeys()) {
            logger.info(jobDataMap.getString(triggerKey));
        }
        logger.info("完成获取JobData");
    }
}
